//
//  B_addWLCell_2.m
//  Estate
//
//  Created by heyong on 16/6/20.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "B_addWLCell_2.h"

#import "C_addWLCell_1.h"
#import "B_SwitchCell.h"
#import "B_wuLiaoCell.h"

@implementation B_addWLCell_2

- (UITableView *)tableView{
    if(_tableView==nil){
        _tableView=[[UITableView alloc]initWithFrame:CGRECTS(0, 46,375,195)];
        _tableView.delegate=self;
        _tableView.dataSource=self;
    }
    return _tableView;
}
- (void)setSite:(Site_04_02 *)site{
    _site=site;
    //赋值的同时，刷新cell内部tableView
    [self.tableView reloadData];
}

-(UIView *)topView{
    if(_topView==nil){
        _topView=[[UIView alloc]initWithFrame:CGRECTS(0, 0, 375, 46)];
        _topView.backgroundColor=[UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1.00];
    }
    return _topView;
}
- (UILabel *)titLab{
    if(_titLab==nil){
        _titLab=[[UILabel alloc]init];
        _titLab.font=[UIFont systemFontOfSize:15.];
    }
    return _titLab;
}
- (UIButton *)dleBtn{
    if(_dleBtn==nil){
        _dleBtn=[[UIButton alloc]init];
    }
    return _dleBtn;
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.topView];
        
        //颜色条
        UIView *line=[[UIView alloc]init];
        [self.topView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(0);
            make.top.mas_offset(0);
            make.bottom.mas_offset(0);
            make.width.offset(4);
        }];
        line.backgroundColor=[UIColor colorWithRed:0.07 green:0.53 blue:0.49 alpha:1.00];
        
        //文字
        [self.topView addSubview:self.titLab];
        [self.titLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.topView.mas_centerY);
            make.left.mas_equalTo(line.mas_right).mas_offset(10);
            make.width.mas_offset(60);
            make.height.mas_offset(40);
        }];
        
        //移除按钮
        [self.topView addSubview:self.dleBtn];
        [self.dleBtn setImage:[UIImage imageNamed:@"quxiao"] forState:UIControlStateNormal];
        [self.dleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.topView.mas_centerY);
            make.right.mas_offset(-10);
            make.width.offset(30);
            make.height.offset(30);
        }];
        [self.dleBtn addTarget:self action:@selector(dleAction) forControlEvents:UIControlEventTouchUpInside];
        
        //添加表格
        [self.contentView addSubview:self.tableView];
        self.tableView.bounces=NO;
        self.tableView.tableFooterView=[[UITableView alloc]initWithFrame:CGRectZero];
        [self.tableView registerNib:[UINib nibWithNibName:@"C_addWLCell_1" bundle:nil] forCellReuseIdentifier:@"cCell"];
        [self.tableView registerNib:[UINib nibWithNibName:@"B_SwitchCell" bundle:nil] forCellReuseIdentifier:@"sCell"];
        [self.tableView registerNib:[UINib nibWithNibName:@"B_wuLiaoCell" bundle:nil] forCellReuseIdentifier:@"wCell"];
    }
    return  self;
    
}

#pragma mark-methold
- (void)dleAction{
    if(self.deleteBlock){
        self.deleteBlock();
    }
}

#pragma  mark -tableViewDelagate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row==2){
        return 100*BIZ;
    }else{
        return 44*BIZ;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    long row=indexPath.row;
    if(row==0){
        C_addWLCell_1 *cell=[tableView dequeueReusableCellWithIdentifier:@"cCell" forIndexPath:indexPath];
        cell.title1.text=@"部位";
        cell.title2.text=@"实测温度℃";
        
        cell.text1ValueChangedBlock=^(NSString *value){
            self.text1Block(value);
        };
        
        cell.text2ValueChangedBlock=^(NSString *value){
            self.text2Block(value);
        };
        
        cell.text1.text=_site.buw;
        cell.text2.text=_site.shic;
        
        return cell;
        
    }else if (row==1){
        B_SwitchCell *cell=[tableView dequeueReusableCellWithIdentifier:@"sCell" forIndexPath:indexPath];
        cell.title.font=[UIFont systemFontOfSize:16*BIZ];
        cell.title.text=@"是否符合方案要求";
        cell.sValueChangeBlock=^(UISwitch *sender){
        
            self.s1Block(sender);
        };
        if([_site.is_1 isEqualToString:@"是"]){
            [cell.kaiguan  setOn:YES];
        }else{
            [cell.kaiguan setOn:NO];
        }
        
        return cell;
    }else {
        B_wuLiaoCell *cells=[tableView dequeueReusableCellWithIdentifier:@"wCell" forIndexPath:indexPath];
        cells.title.text=@"备注";
        cells.textValueChangedBlock=^(NSString *value){
            self.text3Block(value);
        };
        cells.text.text=_site.beiz;
        
        return cells;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
